package com.ifsaid.im.common.service.impl;

import com.ifsaid.im.common.mapper.IBaseMapper;
import com.ifsaid.im.common.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * All rights Reserved, Designed By www.fujica.com.cn
 *
 * @description: 通用 service 实现类
 * @author: Wang Chen Chen<932560435@qq.com>
 * @date: 2019/5/13 20:33
 * @version: 1.0
 * @copyright: 2019 http://www.fujica.com.cn/ Inc. All rights reserved.
 */

public class BaseServiceImpl<ID, T, M extends IBaseMapper<ID, T>> implements IBaseService<ID, T> {

    @Autowired
    protected M baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(ID id) {
        return baseMapper.findById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer save(T entity) {
        return baseMapper.save(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer update(T entity) {
        return baseMapper.update(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteById(ID id) {
        return baseMapper.deleteById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer count(ID id) {
        return baseMapper.count(id);
    }

}
